<script lang="ts" setup>
import debounce from "@/utils/debounce";
import TextEllipsis from "@/components/TextEllipsis/TextEllipsis.vue";

interface ChatItemProps {
  messageId?: string;
  bgColor?: string;
  color?: string;
  article: {
    img: string;
    title: string;
    id: string;
    desc: string;
  };
}
const props = withDefaults(defineProps<ChatItemProps>(), {
  color: "#333333"
});

const onClick = debounce(async (article: ChatItemProps["article"]) => {
  if (article.id) {
    uni.navigateTo({
      url: "/pages/article/article?news_id=" + article.id
    });
  }
});
</script>
<template>
  <view class="bubble robot-bubble">
    <view class="content">
      <view
        class="text"
        :style="{ background: bgColor }"
        @click="onClick(article)"
      >
        <image class="thumb" :src="article.img"></image>
        <view class="info">
          <TextEllipsis
            :custom-style="{
              fontSize: '28rpx',
              color: '#333333'
            }"
            >{{ article.title }}</TextEllipsis
          >
          <TextEllipsis
            :row-count="2"
            :custom-style="{
              fontSize: '24rpx',
              color: '#666666'
            }"
            >{{ article.desc }}</TextEllipsis
          >
        </view>
      </view>
    </view>
  </view>
</template>
<style lang="scss" scoped>
.bubble {
  position: relative;
  width: 100%;
  box-sizing: border-box;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  margin-top: 40rpx;
  .content {
    color: #17181c;
    font-size: 14px;
    box-sizing: border-box;
    word-wrap: break-word;
    max-width: 100%;
    text-align: justify;
    position: relative;
  }

  .text {
    padding: 16rpx;
    border-radius: 10rpx;
    border-top-left-radius: 0;
    background-color: var(--bg-robot-bubble);
    display: flex;
    align-items: center;
    .thumb {
      flex-shrink: 0;
      width: 140rpx;
      height: 140rpx;
      border-radius: 20rpx;
      margin-right: 24rpx;
    }
    .info {
      width: 266rpx;
    }
    .prize {
      color: #ff4949;
      font-size: 32rpx;
      margin-right: 12rpx;
    }
    .old_prize {
      color: #999999;
      font-size: 24rpx;
      text-decoration: line-through;
    }
  }
}
</style>
